package com.android.gufengmall;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.android.gufengmall.gen.DaoMaster;
import com.android.gufengmall.gen.DaoSession;

/**
 * 全局类入口，初始化一些数据
 */
public class App extends Application {

    private static Application mContext;
    private DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;

        initGreenDao();
    }

    /**
     * greendao数据库初始化
     */
    private void initGreenDao() {
        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(this, "gu_Mall.db");
        SQLiteDatabase db = devOpenHelper.getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
    }


    /**
     * 获取 DaoSession
     *
     * @return DaoSession
     */
    public DaoSession getDaoSession() {
        return daoSession;
    }

    public static Context getApp() {
        return mContext;
    }
}
